package com.icss.daos;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.icss.beans.ScheduleVO;

public class ScheduleDao {
	/*日程安排*/
	Dao dao=null;
	
	public void insertSchedule(String personName,Date txtSendTimeMIN,Date txtSendTimeMAX,
			String selectCalType,String txtContent,String txtRemark){
		
		dao=new Dao();
		String sql="insert into schedule(schedulePersonName,beginTime,endTime,scheduleType,scheduleContent,scheduleRemark) values('"+personName+"','"+txtSendTimeMIN+"','"+txtSendTimeMAX+"','"+selectCalType+"','"+txtContent+"','"+txtRemark+"')";
		boolean flag=dao.execute(sql);
		if(flag==true){
		 System.out.println("日程安排添加成功！");
		}else{System.out.println("日程安排添加失败！");}
	}
	public List<ScheduleVO> selectSchedule(Date txtSendTimeMIN,Date txtSendTimeMAX,
			String selectCalType,String txtRemark,String schedulePersonName){
	    List<ScheduleVO> list=new ArrayList<ScheduleVO>();
		dao=new Dao();
		String sql=null;
		if(selectCalType.equals("所有")){
			sql="select * from Schedule where scheduleType<>''";
		}else{sql="select * from Schedule where scheduleType='"+selectCalType+"'";}
		if(txtSendTimeMIN!=null){
			sql = sql + " and beginTime like    '"+txtSendTimeMIN+"'";
		}
		if(txtSendTimeMAX!=null){
			sql = sql + " and endTime like   '"+txtSendTimeMAX+"'";
		}
		if(txtRemark!=null&&txtRemark!=""){
			sql = sql + " and scheduleRemark like  '"+txtRemark+"'";
		}
		if(schedulePersonName!=null&&schedulePersonName!=""){
			sql=sql+"and schedulePersonName like '"+schedulePersonName+"'";
		}
		System.out.println("SQL语句为："+sql);
	    ResultSet rs= dao.query(sql);
	    
	    try {
			while(rs.next()){
				ScheduleVO vo=new ScheduleVO();
				vo.setSchedulePersonName(rs.getString("schedulePersonName"));
				vo.setBeginTime(rs.getDate("beginTime"));
				vo.setEndTime(rs.getDate("endTime"));
				vo.setScheduleType(rs.getString("scheduleType"));
				vo.setScheduleContent(rs.getString("scheduleContent"));
				vo.setScheduleRemark(rs.getString("scheduleRemark"));
				System.out.println("查询成功，RS不为空");
				list.add(vo);
				
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;

	}
	public List selectScheduleAll(){
		List list=new ArrayList();
		
		
		
		return list;

	}
	

}
